package io.renren.modules.business.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import io.renren.modules.business.entity.BusProjectTeamEntity;
import io.renren.modules.business.service.BusProjectTeamService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;

/**
 * 开发团队管理
 *
 * @author liao mengqing
 */
@RestController
@RequestMapping("business/team")
public class BusProjectTeamController {
    @Autowired
    private BusProjectTeamService busProjectTeamService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("business:team:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = busProjectTeamService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{teamId}")
    @RequiresPermissions("business:team:info")
    public R info(@PathVariable("teamId") Long teamId){
		BusProjectTeamEntity busProjectTeam = busProjectTeamService.getById(teamId);

        return R.ok().put("busProjectTeam", busProjectTeam);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("business:team:save")
    public R save(@RequestBody BusProjectTeamEntity busProjectTeam){
		busProjectTeamService.save(busProjectTeam);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("business:team:update")
    public R update(@RequestBody BusProjectTeamEntity busProjectTeam){
		busProjectTeamService.updateById(busProjectTeam);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("business:team:delete")
    public R delete(@RequestBody Long[] teamIds){
		busProjectTeamService.removeByIds(Arrays.asList(teamIds));

        return R.ok();
    }

    /**
     * 查询团队信息列表
     *
     * @return
     */
    @RequestMapping("/select")
    @RequiresPermissions("business:team:select")
    public R select(){
        List<BusProjectTeamEntity> list = busProjectTeamService.selectList();
        return R.ok().put("teamList", list);
    }

}
